package com.woniu.controller;


import com.woniu.util.DescribeCaptchaResult;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
@RequestMapping("/slide")
@Api(tags = "滑动验证模块")
public class TCodeController extends HttpServlet {

    @PostMapping("/login")
    @ResponseBody
    public void loginAd(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String ticket = request.getParameter("ticket");
        String randstr = request.getParameter("randstr");
        System.out.println(ticket);
        System.out.println(randstr);
        //拿到传过来的票据和rangdstr随机字符串来进行校验
        DescribeCaptchaResult describeCaptchaResult = new DescribeCaptchaResult();
        //向客户端发送字符数据——输出流
        PrintWriter out = response.getWriter();
        //向客户端响应一个结果
        if (describeCaptchaResult.codeResponse(ticket,randstr)){
            out.println("ok");
        }else{
            out.println("false");
        }
    }
}
